<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import Editor from '@/components/Editor/index.vue'
import isEmpty from 'lodash/isEmpty'
import { FormInstance } from '@arco-design/web-vue'
const props = defineProps<{
  show: boolean
  id: number | string
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  detail: '',
  id: '',
  name: '',
  sort: 0,
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query = Object.assign({}, detail)
      post({ url: '/server-shop/admin/seller/type/submit', data: query }, ({ code, msg }) => {
        message({
          type: code == 200 ? 'success' : 'error',
          content: msg,
        })
        emit('update:show', false)
        emit('confirm')
        done(true)
      })
    } else done(false)
  })
}
const getInfo = () => {
  get({ url: '/server-shop/admin/seller/type/info', data: { id: props.id } }, ({ data }) => {
    Object.assign(detail, data)
  })
}
onMounted(() => {
  if (props.id) getInfo()
})
</script>
<template>
  <CModal v-model:visible="props.show" @before-ok="submit" :mask-closable="false" width="500px" :title="props.id ? '编辑' : '新建'" @cancel="emit('update:show', false)">
    <div class="content">
      <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item label="类型名称" field="name" :rules="[{ required: true, message: '请输入类型名称' }]" :validate-trigger="['change', 'blur']">
          <a-input v-model="detail.name" placeholder="请输入类型名称" />
        </a-form-item>

        <a-form-item label="排序" field="sort" :rules="[{ required: true, message: '请输入排序' }]" :validate-trigger="['change', 'blur']">
          <a-input-number :min="0" hide-button v-model="detail.sort" placeholder="请输入排序" />
        </a-form-item>
        <a-form-item label="详情" field="detail" :rules="[{ required: true, message: '请输入详情' }]" :validate-trigger="['change', 'blur']">
          <a-textarea v-model="detail.detail" placeholder="请输入详情" />
        </a-form-item>
      </a-form>
    </div>
  </CModal>
</template>
<style lang="less" scoped></style>
